ff9fc8
@@ -813,10 +813,9 @@
static ExprNodeDesc getXpathOrFuncExprNodeDesc(ASTNode expr,
 
           if (inferTypes.contains(constType) && inferTypes.contains(columnType)
               && !columnType.equalsIgnoreCase(constType)) {
-            String constValue =
-                ((ExprNodeConstantDesc) children.get(constIdx)).getValue().toString();
+            Object originalValue =  ((ExprNodeConstantDesc) children.get(constIdx)).getValue();
+            String constValue = originalValue.toString();
             boolean triedDouble = false;
-
             Number value = null;
             try {
               if (columnType.equalsIgnoreCase(serdeConstants.TINYINT_TYPE_NAME)) {
@@ -829,12 +828,17 @@
static ExprNodeDesc getXpathOrFuncExprNodeDesc(ASTNode expr,
                 value = new Long(constValue);
               } else if (columnType.equalsIgnoreCase(serdeConstants.FLOAT_TYPE_NAME)) {
                 value = new Float(constValue);
-              } else if (columnType.equalsIgnoreCase(serdeConstants.DOUBLE_TYPE_NAME)
-                  || (columnType.equalsIgnoreCase(serdeConstants.STRING_TYPE_NAME)
-                     && !constType.equalsIgnoreCase(serdeConstants.BIGINT_TYPE_NAME))) {
-                // no smart inference for queries like "str_col = bigint_const"
+              } else if (columnType.equalsIgnoreCase(serdeConstants.DOUBLE_TYPE_NAME)) {
                 triedDouble = true;
                 value = new Double(constValue);
+              } else if (columnType.equalsIgnoreCase(serdeConstants.STRING_TYPE_NAME)) {
+                // Don't scramble the const type information if comparing to a string column,
+                // It's not useful to do so; as of now, there is also a hack in
+                // SemanticAnalyzer#genTablePlan that causes every column to look like a string
+                // a string down here, so number type information is always lost otherwise.
+                boolean isNumber = (originalValue instanceof Number);
+                triedDouble = !isNumber;
+                value = isNumber ? (Number)originalValue : new Double(constValue);
               }
             } catch (NumberFormatException nfe) {
               // this exception suggests the precise type inference did not succeed
